<?php include_once 'inc/usercheck.php';?>
<!doctype html>
<html>
<head>
	<?php include_once "inc/meta.php";?>
	<script type="text/javascript" src="../js/project/createTable.js"></script>
	<script type="text/javascript" src="../js/project/modify.js"></script>
	<link type="text/css" rel="stylesheet" media="screen" href="../css/css_lightbox.css"></link>
</head>

<body>
	<?php include_once "inc/header.php";?>
	<?php include_once "inc/menu.php";?>
	
	
	
	<script type="text/javascript">
		$("#breadcrumb").html(" 會員管理 &nbsp; &gt; &nbsp; 選取推播");

		//修改資訊用陣列
		var modifyDatas = {};
		
		//serviceClass
		var className = "Push";

		//功能列表資訊
		var needFunction = {checkFun:true, needDetail:false, lastFun:true, checkFunWitdh:"20px", checkFunKey:"id", lastFunWitdh:"70px", lastFunName:"推播狀態" };
		var tabFunArray = new Array(
			{checkDB:true, showCursor:false, dataKey:"id", resultKey:"push_status",
				showTrue:"接受推播", functionTrue:"void", imgTrue:"return.png",  
				showFalse:"不接受推播", functionFalse:"void", imgFalse:"cross.png"}
		);

		//table 格式所需資料
		var tbodyArray = {theadId:"listThead", tfootId:"listTfoot", tbodyId:"listTbody", functionName:"queryTable"};

		//table 內容相關資料
		var tableDataArr = {orderData:" account Desc ", pageRow:30, page:1};

		//table 標題
		var tableTitle = new Array(
			["E-MAIL","account","0%"],
			["註冊方式","regist_type","0%"],
			["性別","gender","0%"],
			["居住區域","live_zone","0%"],
			["所在縣市","county","0%"],
			["註冊貓數量","catCount","0%"],
			["註冊狗數量","dogCount","0%"]
		);	

		//table 欄位資料名稱
		var dataArray = ["account", "regist_type2", "gender2", "live_zone2", "county", "catCount", "dogCount"];

		//搜尋條件
		var searchData = {};

		$(function(){	

			$("#tabs").tabs({
				fx : { opacity : "toggle"},
				selected : 0
			});
			
			createThead();
			createTfoot(); 
			createTbody();

			//上傳套件
			addImgUpload("photo", "filePhoto");

			//小日曆物件
			addDatepicker("date_shelves");

			$("#conditions").change(function(){
				tableDataArr['pageRow'] = $("#rowCount").val();
				tableDataArr['page'] = 1;
				createTbody();
			});

			$("#btnSeracher").click(function(){
				searchData = {};
				createTbody();
			});

			$("#btnInsert").click(function(){
				if(!setModifyDatas()){return;}
				insertDatas(className);
			});

			$("#btnUpdate").click(function(){
				if(!setModifyDatas()){return;}
				modifyDatas['id'] = $("#dataId").val();
				updateDatas(className);
			});

			$("#atab1").click(function(){
				$("#atab2").html("新增");
				$("#btnUpdate").hide();
				$("#btnInsert").show();
				cleanData();
			});

			$("#atab2").click(function(){
				$("#btnUpdate").hide();
				$("#btnInsert").show();
				cleanData();
			});

			$("#btnPueh").click(function(){
				checked_item_count_for_now = getCheckedCount();
				$("#wordSelectCountForNow").html("&nbsp;已選取&nbsp;" + checked_item_count_for_now + "&nbsp;筆資料");
				$("#fade").fadeIn(300, function(){
					$("#pushSetting").fadeIn(300);
				});
			});

			$("#btnSendPush").click(function(){

				var checked_item 	= new Array();
				var pushMessage		= $("#txtMessageForNow").val();
				
				$("input:checkbox[name='checkboxGroup']").each(function(){
				    if($(this).is(":checked")){
				    	checked_item.push($(this).val());
				    }
				});

				$.ajax({
					url : config.functionPath + "PushS.php?action=sendPush",
					dataType: "json" ,
					type: 'POST',
					cache : false,
					data : { datas : { 
						checkedItem	: checked_item,
						message		: pushMessage
				 	}},
					beforeSend :function (){ showWait('資料修改中...'); } 
				}).done(function(result){	
					hideWait();
					checkAjaxResult(result);
					location.reload();
				}).fail(function (error){	
					hideWait(); alert(error.responseText); 	
				}); 
				
			});
			
		});			

		function toStop(dataId){
			modifyDatas = {};
			modifyDatas['id'] 		= dataId;
			modifyDatas['is_shelves'] 	= 0;
			updateDatas(className, dataId);
		}

		function toReturn(dataId){
			modifyDatas = {};
			modifyDatas['id'] 		= dataId;
			modifyDatas['is_shelves'] 	= 1;
			updateDatas(className, dataId);
		}

		function toEdit(dataId){
			$("#atab2").html("修改").click();
			$("#btnInsert").hide();
			$("#btnUpdate").show();
	 		getDatas(className, dataId);
		} 	

	 	function dataInside(){
	 		$("#dataId").val(modifyDatas['id']);
	 		$("#title").val(modifyDatas['title']);
	 		$("#photo").attr("src", config.newsPhotoPath + ( modifyDatas['photo'] == "" ? "notUpload.jpg" : modifyDatas['photo']));
	 		$("#content").html(modifyDatas['content']);
	 		$("#date_shelves").val(modifyDatas['date_shelves']);
	 	}

		function toDelete(dataId){
			deleteDatas(className, dataId);
		}

		function cleanData(){
			$("#dataId").val("");
	 		$("#title").val("");
	 		$("#photo").attr("src", "../images/notUpload.jpg");
	 		$("#content").html("");
	 		$("#date_shelves").val("");
		}

		function setModifyDatas(){
			if(!checkData()){return false;} 
			modifyDatas = {};
			modifyDatas['password'] = $("#password").val();
			modifyDatas['name'] 	= $("#name").val();
			return true;
		}

		//取得已選取數量
		function getCheckedCount(){
			var checked_item_count = 0;
			$("input[name='checkboxGroup']").each(function(){
			    var thisCheckbox = $(this);
			    if(thisCheckbox.is(":checked")){
			    	checked_item_count++;
			    }
			});
			return checked_item_count;
		}

		//關閉推播視窗
		function closeLightbox(nowOpenId){
			$("#" + nowOpenId).fadeOut(300, function(){
				$("#fade").fadeOut(300);
			});
		}
			
		function checkData(){

			/*
			var reg=/\w{4,16}/;  
			var regChina = /[ ,\\`,\\~,\\!,\\@,\#,\\$,\\%,\\^,\\+,\\*,\\&,\\\\,,\\?,\\|,\\:,\\.,\\<,\\>,\\{,\\},\\(,\\),\\',\\;,\\=,\"]/;
			var noHtmlTag = /<[^>]+>/;
			var noScript = /<[Ss][Cc][Rr][Ii][Pp][Tt]|<\/[Hh][Tt][Mm][Ll]|<\/[Bb][Oo][Dd][Yy]|<\?|\?>|<%|%>|<!--|-->/;
			var checkArray = new Array(
				["password","密碼"],
				["name","名稱"]
			);

			for(var i in checkArray){
				if($("#"+checkArray[i][0]).val()==""){
					alert("請輸入"+checkArray[i][1]);
					$("#"+checkArray[i][0]).focus().select(); 
					return false;
				}
			}

			if(!reg.test($("#password").val())){        
	            alert("請輸入4~16位英數字!");
		 		$("#password").focus().select();
		        return false;
			}   

			if(regChina.test($("#name").val())){
				alert("請勿輸入符號!");
				$("#name").focus().select();
				return false;
			}
			*/
				
			return true;
		}

	</script>
	
	<!-- main -->
	<div class="main-content-wapper">
		<input type="hidden" id="dataId"/>
		<div id="tabs">
			<ul>
				<h3 style:"float:left;">選取推播</h3>
				<li><a href="#tab1" id="atab1">列表</a></li>
				<!-- 
				<li><a href="#tab2" id="atab2">新增</a></li>
				 -->
				
			</ul>
			<div id="tab1">
				
				<div style="float:left; display: inline; margin: 0 0 15px 0;">
					<!-- 
					標題 : <input id="searchTitle" type="text" size="15" />
					類別 : 
						<select id="searchType" >
							<option value="0">全部</option>
				  		</select>
					上線時間 : <input id="searchStartDate" type="text" size="10" readonly/> ~ 
							  <input id="searchEndDate" type="text" size="10" readonly/>
					<input type="button" class="button" id="btnSeracher" value="篩選" />
					 -->
					<input type="button" class="button" id="btnPueh" style="float:right;" value="推播" />
				</div>
				 
				
				 
				<div id="conditions" algin="right" style="display:inline; float:right;">
					每頁筆數:
					<select id="rowCount" >
						<option value="10">10</option>
						<option value="20">20</option>
			        	<option value="30" selected>30</option>
			   			<option value="40">40</option>
			   			<option value="50">50</option>
			  		</select>
			    </div>
			    <br />
               	<table class="table" width="100%" >
	               	<thead id="listThead"></thead>
	               	<tbody id="listTbody"></tbody>
	               	<tfoot id="listTfoot"></tfoot>
               	</table>
		    </div> 
			<!-- End #tab1 -->  
			<!--  
			<div id="tab2">
				<table class="table">
					<tr>
						<th colspan="2"><div align="center">最新消息</div></th>
					</tr>
					<tbody id="modifyNameAndDate"></tbody>
					<tr>
						<td width="200px"><b>標題</b></td>
						<td><input type="text" id="title" size="100"/></td>
					</tr>
					<tr>
						<td><b>照片</b></td>
						<td>
							<img id="photo" src="../images/notUpload.jpg"></img>
			                <input type="file" id="filePhoto"></input>
			                <!-- ※建議圖片大小260*66，檔案不得超過1MB，不得使用中文 --> <!-- 
						</td>
					</tr>
					<tr>
						<td><b>內容</b></td>
						<td>
							<textarea  id="content"/></textarea>
						</td>
					</tr>
					<tr>
						<td><b>發送時間</b></td>
						<td><input type="text" id="date_shelves" readonly/></td>
					</tr>
					<tr>
						<td colspan="2">
							<div align="center">
								<input class="button" type="button" id="btnUpdate" style="display: none;" value="修改" />
								<input class="button" type="button" id="btnInsert" style="display: none;" value="新增" />
							</div>
						</td>
					</tr>
				</table>
			</div>
			-->
			
			
			
		</div>	
	</div>
	
	<div id="pushSetting" class="white_content">
    	<div style="margin-top:5px;">
			<span class="searchText" id="wordSelectCountForNow"></span>
	        <div class="close" style="margin:5px;">
	        	<img id="closeNewMessageLightbox" src="/payment/view/admin/images/lightbox_close.png" width="46" height="46" style="cursor:pointer; float:right; margin-top:-35px;" onclick="closeLightbox('pushSetting');"/>
	        </div><br/>
	       	<input id="txtMessageForNow" type="text" class="inputText" size="70" maxLength="35" />
	        <input id="btnSendPush" value="發送推播" class="button" type="button" />
	    </div>
    </div>
	<div id="fade" class="black_overlay"></div>
	
	<?php include_once "inc/footer.php";?>
</body>
</html>